package fr.ralmn.OgameDroid;

import java.util.ArrayList;
import java.util.List;

import fr.ralmn.OgameDroid.Object.Objects;
import fr.ralmn.OgameDroid.actionBar.ActionBarActivity;

import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

/**
 * @author ralmn
 * 
 */
public class OgameDroidActivity extends ActionBarActivity {
	/** Called when the activity is first created. */

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		setTitle("OGameDroid");
		ListView lv = (ListView) findViewById(R.id.listView1);
		lv.setAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, getMenu()));
		lv.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				Log.d("RALMN", position + "");

				switch (position) {
				case 0:
					Intent i0 = new Intent(OgameDroidActivity.this,
							RessourcesListActivity.class);
					startActivity(i0);
					break;
				case 1:
					Intent i1 = new Intent(OgameDroidActivity.this,
							TechnoListActivity.class);
					startActivity(i1);
					break;
				default:
					break;
				}
			}
		});

		setTitle(R.string.app_name);
		setTitleColor(Color.BLUE);
		
		Objects.setT();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		super.onOptionsItemSelected(item);
		switch (item.getItemId()) {
		case R.id.menu_WikiGroup:
			Toast.makeText(this, "Selectionner l'item voulue",
					Toast.LENGTH_SHORT);
			break;

		case R.id.wg_techno:
			Intent it = new Intent(OgameDroidActivity.this,
					TechnoListActivity.class);
			startActivity(it);
			break;
		
		case R.id.wg_ressource:
				Intent ir = new Intent(OgameDroidActivity.this, RessourcesListActivity.class);
			startActivity(ir);
			break;
		case R.id.menu_exit:
			finish();
			break;

		default:
			break;
		}

		return true;
	}

	public List<String> getMenu() {
		List<String> list = new ArrayList<String>();
		list.add("Ressources");
		list.add("Technologie");

		return list;
	}

}